package oop6;

/**
 * @author oldliu
 * @since 1.0
 */
public class Student {
    private final String sex;
    private String name;
    private int id;
    private int age;

    public Student() {
        sex = "男";
    }

    public Student(String sex, String name, int id, int age) {
        this.sex = sex;
        this.name = name;
        this.id = id;
        this.age = age;
    }

    public String getSex() {
        return sex;
    }

    //error
//    public void setSex(String s) {
//        this.sex = s;
//    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "学生{" +
                "性别='" + sex + '\'' +
                ", name='" + name + '\'' +
                ", id=" + id +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true; // 如果两个对象是同一个对象，则返回true
        if (obj instanceof Student) {
            Student s = (Student) obj;
            return this.id == s.id && ((this.name == null && s.name == null) || this.name.equals(s.name));
        }
        return false;
    }
}
